#include "tostring.h"
#include <stdarg.h>


std::string toString(const char* format, ...) {
	const int c1024 = 1024;
	char* arr = (char*)malloc(c1024);
	memset(arr, 0, c1024);
	va_list ap;
	va_start(ap, format);
	vsnprintf_s(arr, c1024, c1024, format, ap);
	va_end(ap);
	std::string str(arr);
	free(arr);
	return str;
}



void cc::replace(std::string& str, const std::string& to_replace, const std::string& replace){
	std::string::size_type pos = 0;
	std::string::size_type srcLen = to_replace.size();
	std::string::size_type desLen = replace.size();
	pos = str.find(to_replace, pos);
	while ((pos != std::string::npos)){
		str.replace(pos, srcLen, replace);
		pos = str.find(to_replace, (pos + desLen));
	}
}